<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('询价')"/>
    <link rel="stylesheet" th:href="@{/static/js/plugins/jquery-layout/jquery.layout-latest.css}">
	<!-- <style type="text/css">.table {table-layout:fixed;}</style> -->
</head>

<body class="gray-bg">

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-condition">
            <form id="inquiryHeaderForm" th:action="@{/inquiryHeader/list}" class="form-inline">
                <div class="select-list">
                    <ul>
                        <li class="col-sm-3" style="width: 33%">
                               <label>汇总号：</label>
                               <input id="inquiryTotalCode" name="inquiryTotalCode" />
                        </li>
                        <li class="col-sm-3" style="width: 33%">
                            <button id="inquiryHeaderSearchBtn" type="button" class="btn btn-primary btn-rounded btn-sm"><i class="fa fa-search"></i>&nbsp;搜索</button>
                            <button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置</button>
                            <button id="inquiryHeaderAdvancedSearch" type="button" class="btn btn-primary btn-rounded btn-sm" style="display: none"><i class="fa fa-caret-down"></i>&nbsp;高级搜索</button>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        
        <div class="col-sm-12 select-info order-table">
            <div class="btn-group hidden-xs toolbar" id="inquiryHeaderToolBar" role="group">
                <!-- <a class="btn btn-outline btn-success btn-rounded" onclick="toAddinquiryHeaderRequestHeader()">
                    <i class="fa fa-plus"></i> 新增
                </a> -->
                <a class="btn btn-outline btn-success btn-rounded" onclick="toEditinquiryHeaderRequestHeader()">
                    <i class="fa fa-edit"></i> 编辑
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="toinquiryBatchsubmission()">
                    <i class="fa fa-save"></i> 生成报价单
                </a>
                
            </div>
            <div style="height:360px; overflow:auto;">
            	<table id="inquiryHeader" data-mobile-responsive="true"></table>
            </div>
            <div>
            	<table id="inquiryItem" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>

</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<script type="text/javascript" th:src="@{/static/js/plugins/jquery-layout/jquery.layout-latest.js}"></script>

<!-- Page-Level Scripts -->

<!--  -->
<script type="text/javascript">
	var itemBS = Searcher.createBS('#inquiryHeader',
	        [
	            {checkbox: true},
	            {title: "Id", field:"inquiryId",visible: false},
	            {title: "汇总号", field:"inquiryTotalCode"},
	            {title: "状态",field:"state",
	            	formatter : function (value, row, index) {
	            		if(value ==0) {
	            			return "草稿";
	            		} else if(value == 1) {
	            			return "报价单已生成";
	            		}else {
	            			return value;
	            		}
	            	}	
	            },
	            {title: "公司代码",field:"companyCode"},
	            {title: "采购组织",field:"purchaseOrg"},
	            {title: "采购组",field:"purchaseGrp"},
	            {title: "语言编码",field:"language"},
	            {title: "采购凭证类型",field:"purchaseType"},
	            {title: "货币",field:"currency"},
	            {title: "询价开始日期",field:"beginDate"},
	            {title: "报价截至日期",field:"endDate"}
	        ],{pageList: [5, 10, 15, 50, 100], pageSize : 5}
	);
  
   
    //刷新数据
    function refresh() {
    	searcherBS.refresh();
    }
    
    // 初始化时间插件
    laydate.render({elem: '#requestDate'});
    laydate.render({elem: '#deliveryDate'});
    
    initDictDataSel();//初始化所有字典数据
    /**
     * 跳转至新增页
     */
    function toAddinquiryHeaderRequestHeader() {
        var index=Dialog.openUrl("新增采购订单", ctxPath + '/modules/pricemanagement/inquiry/inquiry_add.html',{area : ['900px','700px'],
            maxmin: true,
            end: function() {}
        });
        layer.full(index);
    }
 
    /**
     * 编辑
     */
    function toEditinquiryHeaderRequestHeader() {
    	//field:"pkId"
        var rowDatas = itemBS.getSelectedRows("inquiryId");
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行进行编辑");
            return;
        }
        var rows=itemBS.getRawData();
        if(rows[0].state==1){
            Dialog.errorMsg("报价单已生成，不允许编辑！");
            return;
        }
		var index = Dialog.openUrl("编辑供应商信息", ctxPath + '/inquiryHeader/toEdit/'+rowDatas,
		    {area : ['900px','700px'],
			  maxmin: true,
		      end: function () {}
		    });
		layer.full(index);
    }
    //报价单产生
    function toinquiryBatchsubmission(){
        layer.load(1,{shade: [0.3, '#393D49']});
    	 var rowDatas = itemBS.getSelectedRows("inquiryId");
        if(rowDatas.length==0){
            layer.closeAll();
            Dialog.errorMsg("至少选择一行！")
            return;
        }
        var row=itemBS.getRawData();
        for (var i in row){
            if(row[i].state==1){
                layer.closeAll();
                Dialog.errorMsg("报价单已生成！")
                return;
            }
        }
    	 var data = {"inquiryId":rowDatas};
    	 $.ajax({
				type: "POST",
				url: ctxPath + "/inquiryHeader/insertBatch",
				data: JSON.stringify(data),//抬头id
				contentType : "application/json;charsetset=UTF-8",//必须
				dataType:"json",//必须
				cache: true,
				async: false,
				error: function (request) {
                    layer.closeAll();
                    Dialog.errorMsg("提交失败！");
				},
				success: function (data) {
                    layer.closeAll();
					Dialog.msg("批量提交成功!",function(){
						itemBS.refresh();
	                    Dialog.closeFrame(window.name)
	                });
				}
		 });
    }
    
    
    function deletePurchRequestHeader() {
        var rowDatas = searcherBS.getSelectedRows("pkId");
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请至少选择一行");
            return;
        }
        Dialog.confirm('确定删除？', function(index){
            Page.ajaxPOST(ctxPath + "/proPurchRequestHeader/delete", {userIds: rowDatas}, function () {
                Dialog.msg("操作成功", function () {
                    searcherBS.refresh();
                });
            });
        });
    }
</script>
</body>
</html>